package com.biubiushop.controller;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.biubiushop.exception.ServiceException;
import com.biubiushop.service.ICommodityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.Serializable;
import java.math.BigDecimal;

/**
 * @author chenjia
 * @date 2019/06/24
 */
@RestController
@RequestMapping("/shareTissue")
@Api(tags = "商品相关模块")
public class CommodityController {

    @Resource
    ICommodityService commodityService;


    @ApiOperation(value = "获取所有商品")
    @ApiImplicitParams({
    })
    @GetMapping("/commodity/v1/getCommodityList")
    public Serializable getCommodityList(String equipmentId) throws Exception {
		if(StrUtil.isEmpty(equipmentId)) {
			throw new ServiceException("设备信息为空");
		}
        JSONObject json = commodityService.getCommodityList(equipmentId);
        return json;
    }


    @ApiOperation(value = "新增或编辑商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commodityId", value = "商品id", required = false),
            @ApiImplicitParam(name = "name", value = "商品名称", required = false),
            @ApiImplicitParam(name = "price", value = "价格", required = false),
            @ApiImplicitParam(name = "length", value = "长度", required = false),
            @ApiImplicitParam(name = "description", value = "说明", required = false),
    })
    @GetMapping("/commodity/v1/editCommodity")
    public Serializable editCommodity(String commodityId, String name, BigDecimal price, Integer length, String description) throws Exception {
        String result = commodityService.editCommodity(commodityId, name, price, length, description);
        return result;
    }
}
